<?php

namespace frontend\controllers;

use common\models\business\BannerBusiness;
use common\models\enu\BannerType;
use common\models\input\ItemSearch;
use common\models\input\ReviewsSearch;
use Yii;

class ReviewsController extends BaseController {

    public function actions() {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
            ],
        ];
    }

    public function actionIndex() {

        $search = new ReviewsSearch();
        $search->setAttributes(Yii::$app->request->get());

        if ($search->pageSize == "" || $search->pageSize == null) {
            $search->pageSize = 10;
        }

        if ($search->page == "" || $search->page == null) {
            $search->page = 1;
        }
        $search->active = 1;
        $dataPage = $search->search(true);
        $items = new ItemSearch();

        if ($items->pageSize == "" || $items->pageSize == null) {
            $items->pageSize = 10;
        }

        if ($items->page == "" || $items->page == null) {
            $items->page = 1;
        }
        $items->active = 1;
        $items = $items->search(true);
        return $this->render("index", [
                    'dataPage' => $dataPage,
                    'items' => $items->data,
                    'right' => BannerBusiness::getByType(BannerType::RIGHT, 1),
        ]);
    }

}
